from vote import get_verify_image, HttpBot
from ocr import get_sub_char_images
import Image,ImageDraw

def write_to_large(all_sub_images, column_number, per_width, per_height):
    width = column_number * per_width;
    height = (len(all_sub_images) / column_number + 1) * per_height
    print width, height
    training_image = Image.new("RGBA", (width, height))
    draw = ImageDraw.Draw(training_image)
    for i in range(len(all_sub_images)):
        sub_image = all_sub_images[i]
        paste_left = i % column_number * per_width
        paste_top = i / column_number * per_height
        print paste_left, paste_top, paste_left + per_width, paste_top + per_height
        print sub_image.size
        training_image.paste(sub_image, (paste_left, paste_top, paste_left + per_width, paste_top + per_height))
#        sub_image.paste(training_image, None)
    training_image.save('training.tif');     

if __name__ == '__main__':
    all_sub_images = []
    bot = HttpBot()
    for i in range(50):
        image_name = get_verify_image(bot)
        sub_images = get_sub_char_images(image_name)
        all_sub_images.extend(sub_images)
    write_to_large(all_sub_images, 30, 25, 28)